.class public Lorg/microemu/app/util/MIDletSystemProperties;
.super Ljava/lang/Object;
.source "MIDletSystemProperties.java"


# static fields
.field private static acc:Ljava/security/AccessControlContext;

.field public static applyToJavaSystemProperties:Z

.field private static initialized:Z

.field private static final permissions:Ljava/util/Map;

.field private static final props:Ljava/util/Map;

.field private static systemPropertiesDevice:Ljava/util/List;

.field private static systemPropertiesPreserve:Ljava/util/Map;

.field private static wanrOnce:Z


# direct methods
.method static constructor <clinit>()V
    .locals 2

    .prologue
    const/4 v1, 0x1

    .line 55
    sput-boolean v1, Lorg/microemu/app/util/MIDletSystemProperties;->applyToJavaSystemProperties:Z

    .line 60
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    sput-object v0, Lorg/microemu/app/util/MIDletSystemProperties;->props:Ljava/util/Map;

    .line 62
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    sput-object v0, Lorg/microemu/app/util/MIDletSystemProperties;->permissions:Ljava/util/Map;

    .line 68
    sput-boolean v1, Lorg/microemu/app/util/MIDletSystemProperties;->wanrOnce:Z

    .line 70
    const/4 v0, 0x0

    sput-boolean v0, Lorg/microemu/app/util/MIDletSystemProperties;->initialized:Z

    return-void
.end method

.method public constructor <init>()V
    .locals 0

    .prologue
    .line 50
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static clearProperty(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "key"

    .prologue
    .line 177
    sget-boolean v1, Lorg/microemu/app/util/MIDletSystemProperties;->applyToJavaSystemProperties:Z

    if-eqz v1, :cond_0

    .line 179
    :try_start_0
    invoke-static {}, Ljava/lang/System;->getProperties()Ljava/util/Properties;

    move-result-object v1

    invoke-virtual {v1, p0}, Ljava/util/Properties;->remove(Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/lang/SecurityException; {:try_start_0 .. :try_end_0} :catch_0

    .line 187
    :cond_0
    :goto_0
    sget-object v1, Lorg/microemu/app/util/MIDletSystemProperties;->props:Ljava/util/Map;

    invoke-interface {v1, p0}, Ljava/util/Map;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Ljava/lang/String;

    return-object p0

    .line 180
    .restart local p0
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 181
    .local v0, e:Ljava/lang/SecurityException;
    sget-boolean v1, Lorg/microemu/app/util/MIDletSystemProperties;->wanrOnce:Z

    if-eqz v1, :cond_0

    .line 182
    const/4 v1, 0x0

    sput-boolean v1, Lorg/microemu/app/util/MIDletSystemProperties;->wanrOnce:Z

    .line 183
    const-string v1, "Cannot update Java System.Properties"

    invoke-static {v1, v0}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    goto :goto_0
.end method

.method private static getDynamicProperty(Ljava/lang/String;)Ljava/lang/String;
    .locals 1
    .parameter "key"

    .prologue
    .line 145
    const-string v0, "microedition.locale"

    invoke-virtual {p0, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 146
    invoke-static {}, Ljava/util/Locale;->getDefault()Ljava/util/Locale;

    move-result-object v0

    invoke-virtual {v0}, Ljava/util/Locale;->getLanguage()Ljava/lang/String;

    move-result-object v0

    .line 148
    :goto_0
    return-object v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method public static getPermission(Ljava/lang/String;)I
    .locals 2
    .parameter "permission"

    .prologue
    .line 199
    sget-object v1, Lorg/microemu/app/util/MIDletSystemProperties;->permissions:Ljava/util/Map;

    invoke-interface {v1, p0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/Integer;

    .line 200
    .local v0, value:Ljava/lang/Integer;
    if-nez v0, :cond_0

    .line 201
    const/4 v1, -0x1

    .line 203
    :goto_0
    return v1

    :cond_0
    invoke-virtual {v0}, Ljava/lang/Integer;->intValue()I

    move-result v1

    goto :goto_0
.end method

.method public static getPropertiesSet()Ljava/util/Set;
    .locals 1

    .prologue
    .line 152
    invoke-static {}, Lorg/microemu/app/util/MIDletSystemProperties;->initOnce()V

    .line 153
    sget-object v0, Lorg/microemu/app/util/MIDletSystemProperties;->props:Ljava/util/Map;

    invoke-interface {v0}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v0

    return-object v0
.end method

.method public static getProperty(Ljava/lang/String;)Ljava/lang/String;
    .locals 3
    .parameter "key"

    .prologue
    .line 105
    invoke-static {}, Lorg/microemu/app/util/MIDletSystemProperties;->initOnce()V

    .line 106
    sget-object v2, Lorg/microemu/app/util/MIDletSystemProperties;->props:Ljava/util/Map;

    invoke-interface {v2, p0}, Ljava/util/Map;->containsKey(Ljava/lang/Object;)Z

    move-result v2

    if-eqz v2, :cond_0

    .line 107
    sget-object v2, Lorg/microemu/app/util/MIDletSystemProperties;->props:Ljava/util/Map;

    invoke-interface {v2, p0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Ljava/lang/String;

    move-object v2, p0

    .line 116
    :goto_0
    return-object v2

    .line 109
    .restart local p0
    :cond_0
    invoke-static {p0}, Lorg/microemu/app/util/MIDletSystemProperties;->getDynamicProperty(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    .line 110
    .local v1, v:Ljava/lang/String;
    if-eqz v1, :cond_1

    move-object v2, v1

    .line 111
    goto :goto_0

    .line 114
    :cond_1
    :try_start_0
    invoke-static {p0}, Lorg/microemu/app/util/MIDletSystemProperties;->getSystemProperty(Ljava/lang/String;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/SecurityException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v2

    goto :goto_0

    .line 115
    :catch_0
    move-exception v0

    .line 116
    .local v0, e:Ljava/lang/SecurityException;
    const/4 v2, 0x0

    goto :goto_0
.end method

.method public static getSystemProperty(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "key"

    .prologue
    .line 122
    :try_start_0
    sget-object v1, Lorg/microemu/app/util/MIDletSystemProperties;->acc:Ljava/security/AccessControlContext;

    if-eqz v1, :cond_0

    .line 123
    invoke-static {p0}, Lorg/microemu/app/util/MIDletSystemProperties;->getSystemPropertySecure(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    .line 128
    :goto_0
    return-object v1

    .line 125
    :cond_0
    invoke-static {p0}, Ljava/lang/System;->getProperty(Ljava/lang/String;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/SecurityException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    goto :goto_0

    .line 127
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 128
    .local v0, e:Ljava/lang/SecurityException;
    const/4 v1, 0x0

    goto :goto_0
.end method

.method private static getSystemPropertySecure(Ljava/lang/String;)Ljava/lang/String;
    .locals 3
    .parameter "key"

    .prologue
    .line 134
    :try_start_0
    new-instance v1, Lorg/microemu/app/util/MIDletSystemProperties$1;

    invoke-direct {v1, p0}, Lorg/microemu/app/util/MIDletSystemProperties$1;-><init>(Ljava/lang/String;)V

    sget-object v2, Lorg/microemu/app/util/MIDletSystemProperties;->acc:Ljava/security/AccessControlContext;

    invoke-static {v1, v2}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0

    move-object v1, p0

    .line 140
    :goto_0
    return-object v1

    .line 139
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 140
    .local v0, e:Ljava/lang/Throwable;
    const/4 v1, 0x0

    goto :goto_0
.end method

.method public static initContext()V
    .locals 1

    .prologue
    .line 93
    invoke-static {}, Ljava/security/AccessController;->getContext()Ljava/security/AccessControlContext;

    move-result-object v0

    sput-object v0, Lorg/microemu/app/util/MIDletSystemProperties;->acc:Ljava/security/AccessControlContext;

    .line 94
    return-void
.end method

.method private static initOnce()V
    .locals 2

    .prologue
    .line 78
    sget-boolean v0, Lorg/microemu/app/util/MIDletSystemProperties;->initialized:Z

    if-eqz v0, :cond_0

    .line 87
    :goto_0
    return-void

    .line 81
    :cond_0
    const/4 v0, 0x1

    sput-boolean v0, Lorg/microemu/app/util/MIDletSystemProperties;->initialized:Z

    .line 85
    const-string v0, "microedition.platform"

    const-string v1, "MicroEmulator"

    invoke-static {v0, v1}, Lorg/microemu/app/util/MIDletSystemProperties;->setProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    .line 86
    const-string v0, "microedition.encoding"

    const-string v1, "file.encoding"

    invoke-static {v1}, Lorg/microemu/app/util/MIDletSystemProperties;->getSystemProperty(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Lorg/microemu/app/util/MIDletSystemProperties;->setProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    goto :goto_0
.end method

.method public static setDevice(Lorg/microemu/device/Device;)V
    .locals 6
    .parameter "newDevice"

    .prologue
    .line 212
    invoke-static {}, Lorg/microemu/app/util/MIDletSystemProperties;->initOnce()V

    .line 214
    sget-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->systemPropertiesDevice:Ljava/util/List;

    if-eqz v4, :cond_0

    .line 215
    sget-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->systemPropertiesDevice:Ljava/util/List;

    invoke-interface {v4}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v2

    .local v2, iter:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v2}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_0

    .line 216
    invoke-interface {v2}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/String;

    invoke-static {v4}, Lorg/microemu/app/util/MIDletSystemProperties;->clearProperty(Ljava/lang/String;)Ljava/lang/String;

    goto :goto_0

    .line 219
    .end local v2           #iter:Ljava/util/Iterator;
    :cond_0
    sget-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->systemPropertiesPreserve:Ljava/util/Map;

    if-eqz v4, :cond_1

    .line 220
    sget-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->systemPropertiesPreserve:Ljava/util/Map;

    invoke-interface {v4}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v4

    invoke-interface {v4}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, i:Ljava/util/Iterator;
    :goto_1
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_1

    .line 221
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    .line 222
    .local v0, e:Ljava/util/Map$Entry;
    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/String;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v5

    check-cast v5, Ljava/lang/String;

    invoke-static {v4, v5}, Lorg/microemu/app/util/MIDletSystemProperties;->setProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    goto :goto_1

    .line 225
    .end local v1           #i:Ljava/util/Iterator;
    .end local v0           #e:Ljava/util/Map$Entry;
    :cond_1
    new-instance v4, Ljava/util/Vector;

    invoke-direct {v4}, Ljava/util/Vector;-><init>()V

    sput-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->systemPropertiesDevice:Ljava/util/List;

    .line 226
    new-instance v4, Ljava/util/HashMap;

    invoke-direct {v4}, Ljava/util/HashMap;-><init>()V

    sput-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->systemPropertiesPreserve:Ljava/util/Map;

    .line 227
    invoke-interface {p0}, Lorg/microemu/device/Device;->getSystemProperties()Ljava/util/Map;

    move-result-object v4

    invoke-interface {v4}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v4

    invoke-interface {v4}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .end local p0
    .restart local v1       #i:Ljava/util/Iterator;
    :goto_2
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_3

    .line 228
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    .line 229
    .restart local v0       #e:Ljava/util/Map$Entry;
    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Ljava/lang/String;

    .line 230
    .local v3, key:Ljava/lang/String;
    sget-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->props:Ljava/util/Map;

    invoke-interface {v4, v3}, Ljava/util/Map;->containsKey(Ljava/lang/Object;)Z

    move-result v4

    if-eqz v4, :cond_2

    .line 231
    sget-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->systemPropertiesPreserve:Ljava/util/Map;

    sget-object v5, Lorg/microemu/app/util/MIDletSystemProperties;->props:Ljava/util/Map;

    invoke-interface {v5, v3}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v5

    invoke-interface {v4, v3, v5}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 235
    :goto_3
    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object p0

    check-cast p0, Ljava/lang/String;

    invoke-static {v3, p0}, Lorg/microemu/app/util/MIDletSystemProperties;->setProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    goto :goto_2

    .line 233
    :cond_2
    sget-object v4, Lorg/microemu/app/util/MIDletSystemProperties;->systemPropertiesDevice:Ljava/util/List;

    invoke-interface {v4, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    goto :goto_3

    .line 237
    .end local v0           #e:Ljava/util/Map$Entry;
    .end local v3           #key:Ljava/lang/String;
    :cond_3
    return-void
.end method

.method public static setPermission(Ljava/lang/String;I)V
    .locals 2
    .parameter "permission"
    .parameter "value"

    .prologue
    .line 208
    sget-object v0, Lorg/microemu/app/util/MIDletSystemProperties;->permissions:Ljava/util/Map;

    new-instance v1, Ljava/lang/Integer;

    invoke-direct {v1, p1}, Ljava/lang/Integer;-><init>(I)V

    invoke-interface {v0, p0, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 209
    return-void
.end method

.method public static setProperties(Ljava/util/Map;)V
    .locals 3
    .parameter "properties"

    .prologue
    .line 191
    invoke-static {}, Lorg/microemu/app/util/MIDletSystemProperties;->initOnce()V

    .line 192
    invoke-interface {p0}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v2

    invoke-interface {v2}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .end local p0
    .local v1, i:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_0

    .line 193
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    .line 194
    .local v0, e:Ljava/util/Map$Entry;
    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object p0

    check-cast p0, Ljava/lang/String;

    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/String;

    invoke-static {p0, v2}, Lorg/microemu/app/util/MIDletSystemProperties;->setProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    goto :goto_0

    .line 196
    .end local v0           #e:Ljava/util/Map$Entry;
    :cond_0
    return-void
.end method

.method public static setProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "key"
    .parameter "value"

    .prologue
    .line 157
    invoke-static {}, Lorg/microemu/app/util/MIDletSystemProperties;->initOnce()V

    .line 158
    sget-boolean v1, Lorg/microemu/app/util/MIDletSystemProperties;->applyToJavaSystemProperties:Z

    if-eqz v1, :cond_0

    .line 160
    if-nez p1, :cond_1

    .line 161
    :try_start_0
    invoke-static {}, Ljava/lang/System;->getProperties()Ljava/util/Properties;

    move-result-object v1

    invoke-virtual {v1, p0}, Ljava/util/Properties;->remove(Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/lang/SecurityException; {:try_start_0 .. :try_end_0} :catch_0

    .line 173
    :cond_0
    :goto_0
    sget-object v1, Lorg/microemu/app/util/MIDletSystemProperties;->props:Ljava/util/Map;

    invoke-interface {v1, p0, p1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Ljava/lang/String;

    return-object p0

    .line 163
    .restart local p0
    :cond_1
    :try_start_1
    invoke-static {p0, p1}, Ljava/lang/System;->setProperty(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    :try_end_1
    .catch Ljava/lang/SecurityException; {:try_start_1 .. :try_end_1} :catch_0

    goto :goto_0

    .line 165
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 166
    .local v0, e:Ljava/lang/SecurityException;
    sget-boolean v1, Lorg/microemu/app/util/MIDletSystemProperties;->wanrOnce:Z

    if-eqz v1, :cond_0

    .line 167
    const/4 v1, 0x0

    sput-boolean v1, Lorg/microemu/app/util/MIDletSystemProperties;->wanrOnce:Z

    .line 168
    const-string v1, "Cannot update Java System.Properties"

    invoke-static {v1, v0}, Lorg/microemu/log/Logger;->error(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 169
    const-string v1, "Continue ME2 operations with no updates to system Properties"

    invoke-static {v1}, Lorg/microemu/log/Logger;->debug(Ljava/lang/String;)V

    goto :goto_0
.end method
